/**
    Copyright (c) 2009 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "BitonicSortRecursiveCPU.h"
#include "BitonicSortLoopCPU.h"
#include "BitonicSortDemo.h"
#include "BitonicSortData.h"

enum SortMode 
{
    SORT_MODE_RECURSIVE,                // sort recursively
    SORT_MODE_LOOP_ONE_STEP,            // sort iteratively in a single step
    SORT_MODE_LOOP_MULT_STEP            // sort iteratively in multiple steps
};

enum SortDir
{
    SORT_DIR_UP,                    // sort in increasing order
    SORT_DIR_DOWN                    // sort in decreasing order
};

/**
    @brief  Manages the different CPU implementations of bitonic sort.
    @author yakiimo02
    @date    09/12/19
*/
class BitonicSortMgr
{
public:
    BitonicSortMgr();
    ~BitonicSortMgr();

    void Create( ID3D11Device* pd3dDevice );
    void Update( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext );
    void Destroy();

    void BeginSort();

    inline void SetSortMode( const SortMode nSortMode ) { m_nSortMode = nSortMode; }
    inline void SetSortDir( const SortDir nSortDir ) { m_nSortDir = nSortDir; }
    inline void    SetResetData( bool bResetData ) { m_bResetData = bResetData; }

    inline SortMode GetSortMode() const { return m_nSortMode; }
    inline SortDir    GetSortDir() const { return m_nSortDir; }
    inline bool        GetResetData() const { return m_bResetData; }

    inline BitonicSortCPU*    GetpActiveBitonicSort() { return m_pActiveBitonicSort; }
    inline bool                IsSortDirUp() const { return ( m_nSortDir == SORT_DIR_UP ); }

protected:
    BitonicSortRecursiveCPU        m_bitonicSortRecursiveCPU;
    BitonicSortLoopCPU            m_bitonicSortLoopCPU;
    BitonicSortDemo                m_bitonicSortDemo;
    BitonicSortData                m_data;
    BitonicSortCPU*                m_pActiveBitonicSort;

    SortMode                    m_nSortMode;                // recursion, loop, or loop step
    SortDir                        m_nSortDir;                    // increasing or decreasing sort
    int                            m_nElemPerFrame;            // number of elements to sort per frame
    bool                        m_bResetData;                // whether to reset data before begin sorting
};
